import { assertEquals } from "asserts";

import { TreeNodeLeetCodeFromJSON } from "../utils/TreeNodeLeetCodeParse.ts";
import { ArrayToCircularDoublyTreeList } from "./ArrayToCircularDoublyTreeList.ts";
import treeToDoublyList from "./index.ts";

Deno.test("er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof", () => {
    const inputs = [
        [
            619,
            933,
            977,
            408,
            879,
            741,
            172,
            889,
            295,
            167,
            396,
            490,
            803,
            754,
            326,
            724,
            423,
            872,
            373,
            746,
            579,
            601,
            781,
            864,
            139,
            195,
            84,
            48,
            811,
            529,
            352,
            355,
            980,
            789,
            425,
            354,
            749,
            890,
            633,
            677,
            282,
            54,
            879,
            239,
            34,
            55,
            220,
            653,
            752,
            397,
            988,
            827,
            57,
            573,
            516,
            614,
            524,
            686,
            179,
            183,
            995,
            0,
            797,
            875,
            961,
            620,
            750,
            241,
            669,
            303,
            719,
            989,
            73,
            509,
            228,
            342,
            655,
            144,
            639,
            294,
            599,
            306,
            115,
            742,
            106,
            590,
            433,
            235,
            673,
            843,
            315,
            828,
            661,
            863,
            994,
            67,
            154,
            177,
            169,
            521,
        ],
        [4, 2, 5, 1, 3],
    ];
    const outputs = [
        [
            875,
            355,
            961,
            724,
            620,
            980,
            750,
            889,
            241,
            789,
            669,
            423,
            303,
            425,
            719,
            408,
            989,
            354,
            73,
            872,
            509,
            749,
            228,
            295,
            342,
            890,
            655,
            373,
            144,
            633,
            639,
            933,
            294,
            677,
            599,
            746,
            306,
            282,
            115,
            167,
            742,
            54,
            106,
            579,
            590,
            879,
            433,
            879,
            235,
            239,
            673,
            601,
            843,
            34,
            315,
            396,
            828,
            55,
            661,
            781,
            863,
            220,
            994,
            619,
            67,
            653,
            154,
            864,
            177,
            752,
            169,
            490,
            521,
            397,
            139,
            988,
            741,
            827,
            195,
            57,
            803,
            573,
            84,
            516,
            977,
            614,
            48,
            524,
            754,
            686,
            811,
            179,
            172,
            183,
            529,
            995,
            326,
            0,
            352,
            797,
        ],
        [1, 2, 3, 4, 5],
    ];

    assertEquals(
        outputs.map(ArrayToCircularDoublyTreeList),
        inputs.map(TreeNodeLeetCodeFromJSON).map(treeToDoublyList),
    );
});
